
<template>
  <div>
  <h2 class="selectCity">城市选择</h2>
  <van-index-bar :index-list="indexList">
    <template v-for="(item,name) in citylist">
       <van-index-anchor :index="name" :key="name"/>
       <van-cell :title="ele.name" v-for="ele in item" :key="ele.id" @click="goHome"/>
       <!-- <van-cell title="文本" />
       <van-cell title="文本" /> -->
    </template>
  </van-index-bar>
  </div>
</template>

<script>
import {getSelectCity} from '../../api/base';
export default {
  created() {
    getSelectCity().then(res=>{
      console.log("360接口数据：",res.data);
      this.citylist = res.data.result.citylist;
      this.indexList = Object.keys(res.data.result.citylist);
    }).catch(err=>console.error('360接口获取数据出错:',err));
  },
  data(){
    return {
      citylist:{},
      indexList:[]
    }
  },
  methods: {
    goHome(event){
      //点击获取当前城市的名称
      let city = event.target.innerText;
      //本地存储
      sessionStorage.setItem('city',city);
      this.$router.push('/');
    }
  },
 
}
</script>

<style scoped>
.selectCity {
  background: #f5f5f5;
}
.title {
  padding: 0.2rem;
}
</style>

